package com.hotel.comm.bean;

import org.apache.commons.lang.StringUtils;

import java.util.Collection;

/**
 * 调用Dubbo服务的返回类
 *
 * @param <T>
 * @author XuSemon
 * @date 2-15-4-10
 */
public class DubboReply<T> implements IReply {
    /**
     *
     */
    private static final long serialVersionUID = 342313241234134L;
    /**
     * 是否正确
     */
    private boolean isSuccess;
    /**
     * 错误代码
     */
    private String replyCode;
    /**
     * 错误原因
     */
    private String replyMsg;
    /**
     * 返回单个类
     */
    private T t;
    /**
     * 返回数据列表
     */
    private Collection<T> collection;

    /**
     * 默认构造函数，返回成功
     */
    public DubboReply() {
        this(true, Constants.REPLY_CODE_SUCCESS, Constants.REPLY_MSG_SUCCESS);
    }

    /**
     * 构造函数，返回失败
     *
     * @param replyCode
     * @param replyMsg
     */
    public DubboReply(String replyCode, String replyMsg) {
        this(false, replyCode, replyMsg, null, null);
    }

    /**
     * 构造函数
     *
     * @param isSuccess
     * @param replyCode
     * @param replyMsg
     */
    public DubboReply(boolean isSuccess, String replyCode, String replyMsg) {
        this(isSuccess, replyCode, replyMsg, null, null);
    }

    /**
     * 构造函数
     *
     * @param isSuccess
     */
    public DubboReply(boolean isSuccess) {
        this(isSuccess, Constants.REPLY_CODE_SYSTEMERROR, Constants.REPLY_MSG_SYSTEMERROR);
    }

    /**
     * 构造函数
     *
     * @param t
     */
    public DubboReply(T t) {
        this(true, t);
    }

    /**
     * 构造函数
     *
     * @param isSuccess
     * @param t
     */
    public DubboReply(boolean isSuccess, T t) {
        this(isSuccess, null, null, t, null);
    }

    /**
     * 构造函数
     *
     * @param collection
     */
    public DubboReply(Collection<T> collection) {
        this(true, collection);
    }

    /**
     * 构造函数
     *
     * @param isSuccess
     * @param collection
     */
    public DubboReply(boolean isSuccess, Collection<T> collection) {
        this(isSuccess, null, null, null, collection);
    }

    /**
     * 构造函数
     *
     * @param isSuccess
     * @param replyCode
     * @param replyMsg
     * @param t
     * @param collection
     */
    public DubboReply(boolean isSuccess, String replyCode, String replyMsg, T t, Collection<T> collection) {
        this.isSuccess = isSuccess;
        this.replyCode = replyCode;
        this.replyMsg = replyMsg;
        this.t = t;
        this.collection = collection;
    }

    public boolean isSuccess() {
        return isSuccess || (StringUtils.equalsIgnoreCase(this.replyCode, Constants.REPLY_CODE_SUCCESS));
    }

    public void setSuccess(boolean isSuccess) {
        this.isSuccess = isSuccess;
    }

    public String getReplyCode() {
        return replyCode;
    }

    public void setReplyCode(String replyCode) {
        this.replyCode = replyCode;
    }

    public String getReplyMsg() {
        return replyMsg;
    }

    public void setReplyMsg(String replyMsg) {
        this.replyMsg = replyMsg;
    }

    public T getT() {
        return t;
    }

    public void setT(T t) {
        this.t = t;
    }

    public Collection<T> getCollection() {
        return collection;
    }

    public void setCollection(Collection<T> collection) {
        this.collection = collection;
    }
}
